﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.EntityModel;

namespace DataAccess
{
    public static class CitationDataAccess
    {
        public static Citation InsertCitation(Citation newPerson)
        {
            BrigadaEntities context = new BrigadaEntities();
            context.AddToCitation(newPerson);
            context.SaveChanges();
            return newPerson;
        }

        public static Citation GetCitationByIdCitation(long idComplaint)
        {
            BrigadaEntities context = new BrigadaEntities();
            var request = (from p in context.Citation
                           where p.Id == idComplaint
                           select p).SingleOrDefault();
            return request;
        }

        public static Citation UpdateCitation(long ciPerson, Citation newInfo)
        {
            BrigadaEntities context = new BrigadaEntities();
            var person = (from p in context.Citation
                          where p.Id == ciPerson
                          select p).Single();
            person.IdComplaint = newInfo.IdComplaint;
            person.IdEmployee = newInfo.IdEmployee;
            person.CitationDate = newInfo.CitationDate;
            person.CitationTime = newInfo.CitationTime;
            context.SaveChanges();
            return person;
        }

        public static List<Citation> GetCitationsByComplaint(long idComplaint)
        {
            BrigadaEntities context = new BrigadaEntities();
            var query = from elem in context.Citation
                        where elem.IdComplaint==idComplaint
                        select elem;
            var allCitations = query.ToList();
            return allCitations;
        }
    }
}
